package Game01;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class GameJPane01 extends JFrame {
    JButton b1 = new JButton("英雄列表");
    JLabel l1 = new JLabel();

    public GameJPane01(String title) {
        super(title);
        GameClass01[] allHero = new GameClass01[3];
        GameClass01 Cao = new GameClass01("曹操", "男", 30, 100);
        GameClass01 Li = new GameClass01("李白", "男", 22, 100);
        GameClass01 Wang = new GameClass01("王昭君", "女", 18, 100);
        allHero[0] = Cao;
        allHero[1] = Li;
        allHero[2] = Wang;
        JPanel jPanel = new JPanel();
        this.setContentPane(jPanel);
        jPanel.setLayout(null);
        b1.setBounds(0, 0, 100, 50);
        l1.setBounds(100, 0, 100, 50);
        jPanel.add(b1);
        jPanel.add(l1);
        b1.addActionListener(new ActionListener() {
            int allHeroAge = 0;

            @Override
            public void actionPerformed(ActionEvent e) {
                for (int i = 0; i < allHero.length; i++) {
                    allHeroAge = allHeroAge + allHero[i].getAge();
                    System.out.println(allHero[i]);
                }
                l1.setText(String.valueOf(allHeroAge));
            }
        });
    }


}
